use cosmwasm_std::Uint128;
use cosmwasm_std::{HumanAddr, StdResult, Storage};
use cosmwasm_storage::ReadonlySingleton;
use cosmwasm_storage::Singleton;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

pub const REWARD_TOKEN_DECIMAL: u128 = 10_000_000_000;
pub const CONFIG_KEY: &[u8] = b"config";

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ConfigInfo {
    /// Owner If None set, contract is frozen.
    pub owner: HumanAddr,
    pub reward_per_block: Uint128,
    pub all_points: u64,
}

pub fn store_config<S: Storage>(storage: &mut S, data: &ConfigInfo) -> StdResult<()> {
    Singleton::new(storage, CONFIG_KEY).save(data)
}

pub fn read_config<S: Storage>(storage: &S) -> StdResult<ConfigInfo> {
    ReadonlySingleton::new(storage, CONFIG_KEY).load()
}
